package com.itheima.dao;


import org.apache.ibatis.annotations.*;
import  com.itheima.pojo.Role;

import java.util.List;

public interface RoleDao {
    @Select("select * from t_role")
    public List<Role> findPageNotQueryString();

    @Select("select * from t_role where name like CONCAT('%',#{queryString},'%')")
    public List<Role> findPage(String queryString);

    @Insert("insert into t_role (name,keyword,description) values(#{name},#{keyword},#{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    public void insertRole(Role role);

    @Select("select id,name,keyword,description from t_role where id=#{roleId}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "keyword",property = "keyword"),
            @Result(column = "description",property = "description"),

            @Result(column = "id",property = "menus",javaType = java.util.LinkedHashSet.class,
            many=@Many(select = "com.itheima.dao.MenuDao.getByRole")),

            @Result(column = "id",property = "permissions",javaType = java.util.Set.class,
                    many=@Many(select = "com.itheima.dao.PermissionDao.getByRole"))
    })
    public Role findById(Integer roleId);

    @Update("update t_role set name=#{name},keyword=#{keyword},description=#{description} where id=#{id}")
    public void updateRole(Role role);

    @Delete("delete from t_role where id=#{roleId}")
    public void delete(Integer roleId);
}
